//
//  ChargeDetailViewController.m
//  云律司
//
//  Created by 韦淋 on 2017/7/3.
//  Copyright © 2017年 test. All rights reserved.
//

#import "ChargeDetailViewController.h"


@interface ChargeDetailViewController ()<JHPickerDelegate,UITextFieldDelegate,UITextViewDelegate>
@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSArray *imageArray;
@property (nonatomic, strong) NSArray *starArray;
@property (nonatomic, strong) NSDictionary *log_Type;
@property (nonatomic, strong) NSDictionary *charge_Type;
@property (nonatomic, strong) NSDictionary *pay_Type;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, assign) NSString *selectStr;
@property (nonatomic, assign) NSInteger seletTag;
@end

@implementation ChargeDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = false;
    self.dataSource = [NSMutableArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initUI];
}
#pragma mark - Private Method
- (void)initUI{
    self.barTitleLable.text = @"收费详情";
    [self getUI];
}
- (void)getUI{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

    scrollView.contentSize = CGSizeMake(0, SCREEN_HEIGHT + 10);
    scrollView.delegate = self;
    [self.view insertSubview:scrollView atIndex:0];
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT * 2)];
    backView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:backView];
    
    for (int i = 0; i < self.titleArray.count; i ++) {
        
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 80 + i * 50, self.view.bounds.size.width - 20, 40)];
        bgView.backgroundColor = [UIColor whiteColor];
        bgView.layer.borderWidth = 1.0f;
        bgView.layer.borderColor = [[UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f] CGColor];
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, 40, 40)];
        view.backgroundColor = [UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f];
        
        UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 90, 40)];
        titleLable.textColor = [UIColor blackColor];
        titleLable.backgroundColor = [UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f];
        titleLable.font = [UIFont systemFontOfSize:13];
        titleLable.text = self.titleArray[i];
        
        UILabel *redStar = [[UILabel alloc] initWithFrame:CGRectMake(130, 0, 10, 40)];
        redStar.textColor = [UIColor redColor];
        redStar.backgroundColor = [UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f];
        redStar.font = [UIFont systemFontOfSize:13];
        redStar.text = self.starArray[i];
        
        [backView addSubview:bgView];
        
        [bgView addSubview:titleLable];
        [bgView addSubview:redStar];
        
        UITextField *inputInfo = [[UITextField alloc] initWithFrame:CGRectMake(160, 80 + i * 50, 200, 40)];
        inputInfo.clearButtonMode = UITextFieldViewModeWhileEditing;
        inputInfo.textAlignment = NSTextAlignmentLeft;
        inputInfo.font = [UIFont systemFontOfSize:13];
        inputInfo.userInteractionEnabled = NO;
        inputInfo.delegate = self;
        inputInfo.tag = i + 100;
        
        if (i == 0) {
            inputInfo.text = self.listDetailDic[@"ah_number"];
        }
        if (i == 1) {
//            inputInfo.text = self.listDetailDic[@"audit_time"];
        }
        if (i == 2) {
            inputInfo.text = self.listDetailDic[@"sfje"];
        }
        if (i == 3) {
            inputInfo.text = self.listDetailDic[@"fylx"];
        }
        if (i == 4) {
            inputInfo.text = self.listDetailDic[@"sflx"];
        }
        
        UIImageView *titleImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
        titleImage.backgroundColor = [UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f];
        titleImage.image = [UIImage imageNamed:self.imageArray[i]];
        
        if (i == self.titleArray.count - 1) {
            bgView.frame = CGRectMake(10, 80 + i * 50, 130, 40);
            inputInfo.hidden = YES;
            
            UITextView *input = [[UITextView alloc] initWithFrame:CGRectMake(10, 80 + (i + 1) * 50, self.view.bounds.size.width - 20, 120)];
            input.layer.borderWidth = 1.0f;
            input.layer.borderColor = [[UIColor colorWithRed:248.0f/255.0f green:248.0f/255.0f blue:248.0f/255.0f alpha:1.0f] CGColor];
            input.autoresizingMask = UIViewAutoresizingFlexibleHeight;
            input.text = @"请填写备注";
            input.tag = 1000;
            input.textColor = [UIColor lightGrayColor];
            input.delegate = self;
            [backView addSubview:input];
            
            
            UIButton *alterButton = [UIButton buttonWithType:UIButtonTypeCustom];
            alterButton.frame = CGRectMake(20, 80 + (i + 1) * 50 + 130, 160, 40);
            [alterButton setTitle:@"通过" forState:UIControlStateNormal];
            alterButton.titleLabel.textColor = [UIColor whiteColor];
            alterButton.layer.cornerRadius = 5;
            alterButton.layer.masksToBounds = YES;
            alterButton.backgroundColor = [UIColor colorWithRed:33.0f/255.0f green:180.0f/255.0f blue:237.0f/255.0f alpha:1.0f];
            [alterButton addTarget:self action:@selector(action_Pass) forControlEvents:UIControlEventTouchUpInside];
            
            UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
            deleteButton.frame = CGRectMake(200, 80 + (i + 1) * 50 + 130, 160, 40);
            [deleteButton setTitle:@"作废" forState:UIControlStateNormal];
            deleteButton.titleLabel.textColor = [UIColor whiteColor];
            deleteButton.layer.cornerRadius = 5;
            deleteButton.layer.masksToBounds = YES;
            deleteButton.backgroundColor = [UIColor colorWithRed:33.0f/255.0f green:180.0f/255.0f blue:237.0f/255.0f alpha:1.0f];
            [deleteButton addTarget:self action:@selector(action_Cancel) forControlEvents:UIControlEventTouchUpInside];
            [backView addSubview:alterButton];
            [backView addSubview:deleteButton];
        }
        [bgView addSubview:titleImage];
        [backView addSubview:inputInfo];
        [bgView insertSubview:view belowSubview:titleImage];
    }
}
#pragma mark - Button Target
- (void)action_Cancel{
    NSLog(@"作废 ");
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetworkingManager postUrl:[NSString stringWithFormat:@"%@",ALTERCHARGES_URL] dic:@{@"id":self.listDetailDic[@"id"],@"zt":@"3"} Succeed:^(id responseData) {NSLog(@"addJobLog :%@",responseData);
        NSLog(@"%@",responseData);
        [MBProgressHUD showError:@"已作废"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [MBProgressHUD showError:@"删除失败"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}
- (void)action_Pass{
    NSLog(@"通过 ");
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [NetworkingManager postUrl:[NSString stringWithFormat:@"%@",ALTERCHARGES_URL] dic:@{@"id":self.listDetailDic[@"id"],@"zt":@"2"} Succeed:^(id responseData) {NSLog(@"addJobLog :%@",responseData);
        NSLog(@"%@",responseData);
        [MBProgressHUD showError:@"已通过"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [MBProgressHUD showError:@"删除失败"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}



#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length < 1){
        textView.text = @"请填写备注";
        textView.textColor = [UIColor lightGrayColor];
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"请填写备注"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}

#pragma mark - Getter
- (NSArray *)titleArray{
    if (!_titleArray) {
        
            _titleArray = [NSArray arrayWithObjects:@"收 款 案 件  ：",@"收 款 日 期  ：",@"交 易 金 额  ：",@"费 用 类 型  ：",@"支 付 方 式： ",@"备 注 说 明  ：",nil];
        
    }
    return _titleArray;
}
- (NSArray *)imageArray{
    if (!_imageArray) {
                   _imageArray = [NSArray arrayWithObjects:@"llist_01",@"llist_02",@"llist_03",@"llist_0",@"llist_05",@"llist_05",nil];
           }
    return _imageArray;
}

- (NSArray *)starArray{
    if (!_starArray) {
        _starArray = [NSArray arrayWithObjects:@"",@"",@"*",@"*",@"*",@"*",@"",nil];
    }
    return _starArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

